﻿#region Copyright and License Notice
// Copyright (C)2010-2016 - Rob Levine and other contributors
// http://configgen.codeplex.com
// 
// This file is part of ConfigGen.
// 
// ConfigGen is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// ConfigGen is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License and 
// the GNU Lesser General Public License along with ConfigGen.  
// If not, see <http://www.gnu.org/licenses/>
#endregion

using ConfigGen.Core.ConfigurationSettings;
using NUnit.Framework;

namespace ConfigGen.Core.Tests
{
    [TestFixture]
    public class ConfigFileNameGeneratorTests
    {
        [Test]
        public void GenerateFilename001()
        {
            const string machineName = "MyTestWorkstation";
            const string configFilePath = "Web.Config";

            var settings = new Preferences
                               {
                                   OutputDirectory = "C:\\MyDirectory\\GeneratedConfigs"
                               };

            var machineConfig = new MachineConfigurationSettings(machineName, configFilePath, new ConfigurationSetting[0]);

            var filenameGeneratorUnderTest = new ConfigFileNameGenerator();
            string filename = filenameGeneratorUnderTest.GenerateFilename(machineConfig, settings);

            const string expectedFilename = @"C:\MyDirectory\GeneratedConfigs\MyTestWorkstation\Web.Config";
            Assert.AreEqual(expectedFilename, filename);
        }

        [Test]
        public void GenerateFilename002_FlatDirectoryOutput()
        {
            const string machineName = "MyTestWorkstation";
            const string configFilePath = "Web.Config";

            var settings = new Preferences
            {
                OutputDirectory = "C:\\MyDirectory\\GeneratedConfigs",
                FlatDirectoryOutput = true
            };

            var machineConfig = new MachineConfigurationSettings(machineName, configFilePath, new ConfigurationSetting[0]);
            
            var filenameGeneratorUnderTest = new ConfigFileNameGenerator();
            string filename = filenameGeneratorUnderTest.GenerateFilename(machineConfig, settings);

            const string expectedFilename = @"C:\MyDirectory\GeneratedConfigs\Web.Config";
            Assert.AreEqual(expectedFilename, filename);
        }

        [Test]
        public void GenerateFilename003_ForcedFilename()
        {
            const string machineName = "MyTestWorkstation";
            const string configFilePath = "Web.Config";

            var settings = new Preferences
            {
                OutputDirectory = "C:\\MyDirectory\\GeneratedConfigs",
                ForcedFilename = "Forced.Web.Config"
            };

            var machineConfig = new MachineConfigurationSettings(machineName, configFilePath, new ConfigurationSetting[0]);

            var filenameGeneratorUnderTest = new ConfigFileNameGenerator();
            string filename = filenameGeneratorUnderTest.GenerateFilename(machineConfig, settings);

            const string expectedFilename = @"C:\MyDirectory\GeneratedConfigs\MyTestWorkstation\Forced.Web.Config";
            Assert.AreEqual(expectedFilename, filename);
        }


        [Test]
        public void GenerateFilename004_MachineSuffix()
        {
            const string machineName = "MyTestWorkstation";
            const string configFilePath = "Web.Config";

            var settings = new Preferences
            {
                OutputDirectory = "C:\\MyDirectory\\GeneratedConfigs",
                MachineSuffix = true,
            };

            var machineConfig = new MachineConfigurationSettings(machineName, configFilePath, new ConfigurationSetting[0]);
            
            var filenameGeneratorUnderTest = new ConfigFileNameGenerator();
            string filename = filenameGeneratorUnderTest.GenerateFilename(machineConfig, settings);

            const string expectedFilename = @"C:\MyDirectory\GeneratedConfigs\MyTestWorkstation\Web.Config.MyTestWorkstation";
            Assert.AreEqual(expectedFilename, filename);
        }
    }
}
